// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AxisAngleTests.cs" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace Test.Robotics.Numerics
{
    using System;

    using Microsoft.Robotics.Numerics;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>
    /// Test AxisAngle struct
    /// </summary>
    [TestClass]
    public class AxisAngleTests
    {
        /// <summary>
        /// Test the constructor of AxisAngle struct
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void TestConstructorFromAUnitRotationalAxisVector()
        {
            double rx = 0.2;
            double ry = 0.3;
            double rz = Math.Sqrt(1 - 0.04 - 0.09);
            double angle = MathConstants.PIOverFour;
            AxisAngle axisAngle = new AxisAngle(new Vector3(rx, ry, rz), angle);
            
            Assert.AreEqual(axisAngle.Angle, angle);
            Assert.AreEqual(axisAngle.Axis.X, rx);
            Assert.AreEqual(axisAngle.Axis.Y, ry);
            Assert.AreEqual(axisAngle.Axis.Z, rz);
        }

        /// <summary>
        /// Test the static method to construct AxisAngle struct from a rotational axis represented by a non-unit vector
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void TestStaticMethodToConstructAxisAngleFromARotationalAxisNonUnitVector()
        {
            double rx = 0.2;
            double ry = 0.3;
            double rz = Math.Sqrt(1 - 0.04 - 0.09);
            double angle = MathConstants.PIOverFour;
            double scalar = 2.0;
            AxisAngle axisAngle = AxisAngle.CreateAxisAngleFromRotationalAxisNonUnitVector(new Vector3(rx, ry, rz) / scalar, angle);

            Assert.AreEqual(angle, axisAngle.Angle, MathConstants.ErrorEpsilon);
            Assert.AreEqual(rx, axisAngle.Axis.X, MathConstants.ErrorEpsilon);
            Assert.AreEqual(ry, axisAngle.Axis.Y, MathConstants.ErrorEpsilon);
            Assert.AreEqual(rz, axisAngle.Axis.Z, MathConstants.ErrorEpsilon);
        }
    }
}
